package com.easylinkin.linkappapi.security.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.FieldNameConstants;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import site.morn.constant.MetricUnit.Text;

import javax.persistence.*;
import java.util.Date;

/**
 * 菜单权限实体
 *
 * @author tulinli
 * @author TianGanLin
 * @since 0.1.1, 2019/5/28
 */
@AttributeOverride(name = "id", column = @Column(name = "id_"))
@AttributeOverride(name = "name", column = @Column(name = "name_", length = 32))
@AttributeOverride(name = "parentId", column = @Column(name = "parent_id_"))
@AttributeOverride(name = "level", column = @Column(name = "level_"))
@AttributeOverride(name = "code", column = @Column(name = "privilege_code_"))
@AttributeOverride(name = "searchCode", column = @Column(name = "search_code_"))
@AttributeOverride(name = "type", column = @Column(name = "type_"))
@AttributeOverride(name = "url", column = @Column(name = "url_"))
@AttributeOverride(name = "sort", column = @Column(name = "seq_"))
@AttributeOverride(name = "tenantId", column = @Column(name = "tenant_id_"))
@AttributeOverride(name = "iconName", column = @Column(name = "icon_name"))
@AttributeOverride(name = "description", column = @Column(name = "description_"))
@AttributeOverride(name = "modifier", column = @Column(name = "modifier_", length = 32))
@AttributeOverride(name = "modifyTime", column = @Column(name = "modify_time_"))
@AttributeOverride(name = "creator", column = @Column(name = "creator_", length = 32))
@AttributeOverride(name = "createTime", column = @Column(name = "create_time_"))
@AttributeOverride(name = "target", column = @Column(name = "target"))
@AttributeOverride(name = "flag", column = @Column(name = "flag_"))
@Data
@DynamicInsert
@DynamicUpdate
@Entity
@FieldNameConstants
@Table(name = "linkapp_privilege")
@ApiModel("权限实体类")
public class LinkappPrivilege implements Comparable {

  /**
   * 是否为操作日志(1是,0否)
   */
  @ApiModelProperty(value = "是否为操作日志", example = "1")
  @TableField("is_log_")
  @Column(name = "is_log_")
  private Integer isLog;

  @TableField("target")
  @Column
  protected String target;


  /**
   * 主键
   */
  @Id
  @TableField("id_")
  @GeneratedValue
  protected Long id;

  /**
   * 父节点
   */
  @ApiModelProperty(value = "父节点", example = "1")
  @Column
  @TableField("parent_id_")
  protected Long parentId;

  /**
   * 层级
   */
  @ApiModelProperty(value = "层级", example = "1")
  @Column
  @TableField("level_")
  protected Integer level;

  /**
   * 查询码
   */
  @ApiModelProperty(value = "查询码", example = "")
  @Column
  @TableField("search_code_")
  protected String searchCode;

  /**
   * 权限名
   */
  @ApiModelProperty(value = "权限名", example = "")
  @TableField("name_")
  @Column(length = Text.SHORT)
  protected String name;

  /**
   * 说明
   */
  @ApiModelProperty(value = "说明", example = "")
  @Column
  @TableField("description_")
  protected String description;

  /**
   * 类型，0:菜单目录（菜单分隔符） 1:菜单 2:按钮
   */
  @ApiModelProperty(value = "类型", example = "1")
  @Column
  @TableField("type_")
  protected Integer type;

  /**
   * 权限码
   */
  @ApiModelProperty(value = "权限码", example = "")
  @Column(length = 32)
  @TableField("privilege_code_")
  protected String code;

  /**
   * 路径
   */
  @ApiModelProperty(value = "路径", example = "")
  @Column
  @TableField("url_")
  protected String url;

  @ApiModelProperty(value = "租户ID", example = "")
  @Column
  @TableField("tenant_id_")
  protected String tenantId;

  @ApiModelProperty(value = "图标", example = "")
  @Column
  @TableField("icon_name")
  protected String iconName;

  /**
   * 排序的序号
   */
  @ApiModelProperty(value = "排序的序号", example = "0")
  @Column
  @TableField("seq_")
  protected Double sort;

  @TableField("create_time_")
  @Column
  private Date createTime;

  @TableField("creator_")
  @Column
  private String creator;

  @TableField("modifier_")
  @Column
  private String modifier;

  /**
   * 权限分类，0为WEB端，1为APP端
   */
  @TableField("flag_")
  @Column
  private Integer flag;

  @TableField("modify_time_")
  @Column
  private Date modifyTime;

@Override
public int compareTo(Object arg0) {
	LinkappPrivilege linkappPrivilege = (LinkappPrivilege)arg0;
	if(this.sort < linkappPrivilege.getSort()) {
		return -1;
	}else {
		if(this.sort > linkappPrivilege.getSort()) {
			return 1;
		}
	}
	return 0;
}

}
